package com.sky.task;

import com.alibaba.fastjson.JSON;
import com.sky.webSocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.HashMap;
import java.util.Map;

/**
 * 定时发送message测试webSocket
 */
//@Component
@Slf4j
public class MyTask {

    @Autowired
    private WebSocketServer webSocketServer;

    @Scheduled(cron = "0 * * * * ?")
    public void sendMsg() {
        webSocketServer.sendMsgToAll("发送测试数据");
    }

    @Scheduled(cron = "1 * * * * ?")
    public void sendMsg2() {
        // 发送客户端消息提醒
        Map<String, Object> map = new HashMap<>();
        map.put("type", 1); //消息类型，1表示来单提醒
        map.put("orderId", 324234);
        map.put("content", "订单号：" + 234234);
        webSocketServer.sendMsgToAll(JSON.toJSONString(map));
        webSocketServer.sendMsgToAll("发送测试数据");
    }
}
